package br.edu.ufcg.lsd.wbis.ui.client.ui.loggedin.admin.leftmenu.user;

import br.edu.ufcg.lsd.wbis.ui.client.beans.UserMatcher.StringMatchingType;

import com.gwtext.client.data.SimpleStore;

/**
 * @author Renato Miceli
 */
public class SearchTypeStore extends SimpleStore {

	String columnName;
	
	public SearchTypeStore(String columnName) {
		super(new String[] { "searchType-" + columnName }, new String[][] {  new String[] { "Default" }, new String[] { "Contains" }, new String[] { "Starts with" }, new String[] { "Ends with" } });
		this.columnName = columnName;
		this.load();
	}

	public static StringMatchingType getMatchingType(String value) {
		if (value.equals("Contains")) {
			return StringMatchingType.CONTAINS;
		} else if (value.equals("Starts with")) {
			return StringMatchingType.STARTS_WITH;
		} else if (value.equals("Ends with")) {
			return StringMatchingType.ENDS_WITH;
		}
		
		return StringMatchingType.DEFAULT;
	}

	public static String getValue(StringMatchingType type) {
		switch(type){
		case CONTAINS:
			return "Contains";
		case STARTS_WITH:
			return "Starts with";
		case ENDS_WITH:
			return "Ends with";
		default:
			return "Default";
		}
	}

	public String getColumnName() {
		return "searchType-" + columnName;
	}

}
